package models

import (
	"doctor-srv/basic/config"
	"gorm.io/gorm"
)

// 处方
type Prescript struct {
	gorm.Model
	PatientId int    `json:"patient_id" gorm:"type:int;comment:'患者id'"`
	DoctorId  int    `json:"doctor_id" gorm:"type:int;comment:'医生id'"`
	RecordId  int    `json:"record_id" gorm:"type:int;comment:'问诊id'"`
	Desc      string `json:"desc" gorm:"type:varchar(200);comment:'处方'"`
	Status    int    `json:"status" gorm:"type:int;comment:'审核状态 1-未审核 2-审核通过 3-审核不通过'"`
}

func (pr *Prescript) TableName() string {
	return "prescript"
}

func (pr *Prescript) AddPrescript() error {
	return config.DB.Create(&pr).Error
}

func (pr *Prescript) GetPrescript(id int) error {
	return config.DB.Model(&Prescript{}).Where("id = ?", id).Limit(1).Find(&pr).Error
}

func (pr *Prescript) UpdateStatus(id int) error {
	return config.DB.Model(&Prescript{}).Where("id = ?", id).Updates(&pr).Find(&pr).Error
}
